//package com.kh.first.controller;
//
//import com.kh.first.pojo.UserPojo;
//import com.kh.first.pojo.common.AjaxJson;
//import com.kh.first.utils.UserUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.Model;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpSession;
//import java.util.Enumeration;
//

////自己用的程序不需要这个
//@Controller
//@RequestMapping("loginController")
//public class LoginController {
//
//    public static final String goLogin = "loginController.do?goLogin";
//    public static final String homeUrl = "my_easyui/index";
//    public static final String home = "loginController.do?home";
//    public static final String loginPage = UserUtils.THEME+"login";
//    public static final String homePage = UserUtils.THEME + "home";
//
//    public static final String mobileLogin = "answer/login";
//    public static final String mobileHomeUrl = "answer/home";
//
//    public static final String adminUrl = homePage;
//
//    public static final String browserErrorPage = UserUtils.THEME+"browser-error";
//
//
//    @Autowired
//    private UserService userService;
//
//    @RequestMapping(params = "goLogin")
//    public String goLogin(UserPojo user, HttpSession session, HttpServletRequest request) {
//
//        String agent = request.getHeader("User-Agent").toLowerCase();
//        if (agent.contains("trident")) {
//            return browserErrorPage;
//        }
//        UserPojo sessionUser = UserUtils.getUser();
//        if (sessionUser != null) {
//            return "redirect:" + home;
//        }
////		return mobileLogin;
//        return loginPage;
//    }
//
//    @RequestMapping(params = "doLogin")
//    @ResponseBody
//    public AjaxJson<String> doLogin(UserPojo user) {
//        AjaxJson<String> ajaxJson = new AjaxJson<>();
//        UserPojo user2 = userService.getUserByNamePwd(user);
//
//        if (user2!=null) {
//            Integer status = user2.getDelStatus();
//            if (UserPojo.not_del != status) {
//                ajaxJson.code=(-3);
//                ajaxJson.data=("无法登陆，因为您已经离职");
//                return ajaxJson;
//            }
//            UserUtils.setUser(user2);
//        } else {
//            // 不存在用户
////			return "redirect:" + goLogin;
//            ajaxJson.code=(-2);
//            ajaxJson.data=("用户不存在,或者密码错误");
//        }
//        return ajaxJson;
//    }
//    // http://localhost:1234/learn/loginController.do?home
//    @RequestMapping(params = "home")
//    public String doLogin(UserPojo user, HttpSession session, HttpServletRequest request,Model model) {
//
//        // KHUser sessionUser = (KHUser) session.getAttribute(UserUtils.KH_USER);
//        UserPojo sessionUser = UserUtils.getUser();
//        System.out.println("sessionUser::" + sessionUser);
////        String staffNo =null;
////        if(null!=sessionUser)
////            staffNo=sessionUser.getStaffNo();
//        if ( null == sessionUser) {
////            request.setAttribute("msg", "用户工号为空");
//            return "redirect:" + goLogin;
//        }
//
//        model.addAttribute("user", sessionUser);
//        return adminUrl;
//    }
//
//    @RequestMapping(params = "logout")
//    @ResponseBody
//    public AjaxJson logout(HttpSession session) {
//        AjaxJson ajaxJson=new AjaxJson();
//        // session.setAttribute(UserUtils.KH_USER, null);
//        Enumeration<String> em = session.getAttributeNames();
//        while (em.hasMoreElements()) {
//            session.removeAttribute(em.nextElement().toString());
//        }
//        return ajaxJson;
////		return "redirect:" + goLogin;
//    }
//
//}
